package game.view.panel.game
{
	import com.base.type.LayerEnum;
	
	import flash.events.*;
	
	import game.GlobalConfig;
	import game.controller.mediator.MyRecordMediator;
	import game.model.GameData;
	import game.model.type.*;
	import game.util.*;
	import game.view.base.gamepanel.MyRecordPanelUI;
	
	import morn.App;
	import morn.core.components.*;
	import morn.core.components.Box;
	import morn.core.handlers.Handler;
	public class MyRecordPanel extends MyRecordPanelUI
	{
		private var myreList:Array=[];
		public function MyRecordPanel()
		{
			super();
			setLayerType(LayerEnum.LAYER_SINGLE);
			setMediatorClass(MyRecordMediator);
		}
		override protected function initialize():void
		{
			super.initialize();
			closeBtn.addEventListener(MouseEvent.CLICK,closeBtnClick);
			nodata.visible=false;
			recdList.renderHandler = new Handler(itemChildren);
			
		}
		override protected function reset():void
		{
			super.reset();		
		}
		override protected function updateData(data:Object):void
		{
			//trace('MyRecordPanel updateData',data);
			if(data is Array){
				var list:Array=(data as Array); 
				recdList.array=list;
				nodata.visible=(list.length>0?false:true);
			}
			
		}
		public function setData(data:Object=null):void{
			trace('MyRecordPanel setData',data);
		}
		private function itemChildren(item:Component,index:int):void
		{
			if (index<recdList.length)
			{
				var data:Object = item.dataSource as Object;
				var batchList:Array=data.batchList;
				
				
				var labelTxt:String='';
				for(var i:int=0;i<batchList.length;i++){
					/*var ndate:Date=new Date(batchList[i].createTime);
					var _s:String=(ndate.hours>=10?ndate.hours.toString():"0"+ndate.hours.toString());
					var _f:String=(ndate.minutes>=10?ndate.minutes.toString():"0"+ndate.minutes.toString());
					var _m:String=(ndate.seconds>=10?ndate.seconds.toString():"0"+ndate.seconds.toString());
					var timerStr:String=ndate.fullYear+"-"+(ndate.month+1)+"-"+ndate.date+'  '+_s+":"+_f+":"+_m;
					var lestr:String=(batchList[i].jumpStatus==0?"第"+(i+1)+"关":"<font color='#09EFA4'>失败</font>");
					var awName:String=(batchList[i].awardName!=""?'获得'+batchList[i].awardName:'');
					awName=setNameStr(awName,30);
					var gsstr:String=(batchList[i].jumpStatus==0?"    <font color='#09EFA4'>"+awName+"</font>    ":setNameStr('',40));
					var sss:String=timerStr+gsstr+lestr+"<br>";
					labelTxt+=sss;*/
					
					
				}
				
				//var label:Label=item.getChildByName('labelTxt') as Label;
				//label.text=labelTxt;
				//trace(timerStr);
				
				var lIndex:int=0;
				for(var i:int=6;i>=1;i--){
					var timeName:Label=item.getChildByName('time'+i) as Label;
					timeName.text='';
					var gsName:Label=item.getChildByName('gsname'+i) as Label;
					gsName.text='';
					var levelName:Label=item.getChildByName('level'+i) as Label;
					levelName.text='';
					levelName.color=0xFFFFFF;
					if(lIndex<batchList.length){	
						var vo:Object=batchList[lIndex];
						levelName.text='第'+vo.levelId+'关';
						var ndate:Date=new Date(vo.createTime);
						var _s:String=(ndate.hours>=10?ndate.hours.toString():"0"+ndate.hours.toString());
						var _f:String=(ndate.minutes>=10?ndate.minutes.toString():"0"+ndate.minutes.toString());
						var _m:String=(ndate.seconds>=10?ndate.seconds.toString():"0"+ndate.seconds.toString());
						var timerStr:String=ndate.fullYear+"-"+(ndate.month+1)+"-"+ndate.date+'  '+_s+":"+_f+":"+_m;
						timeName.text=timerStr;
						if(vo.jumpStatus==0){
							gsName.text=(vo.awardName!=""?'获得  '+vo.awardName+'*'+vo.amount:'');
						}else{
							levelName.color=0x09EFA4;
							levelName.text='失败';
						}
						lIndex++;
					}
					
				}
				
			}
			
		}
		
		private function setNameStr(str:String,len:int):String{
		
			var i:int=0;
			var _len:int=0;

			for (i = 0; i < str.length; i++)
			{
				
				if(str.charCodeAt(i)>10000){
					_len+=2;
				}else{
					_len+=1;
				}
			
			}
			for(i=_len;i<=len;i++){
			
				str+=' ';
			}
			//trace('str',str,_len);
			return str;
		}
		private function closeBtnClick(e:MouseEvent):void{
			ZooMain.view.closeView(MyRecordPanel);
		}
		
		override protected function dispose():void{
			super.dispose();
		}
	}
}